<template>
  <div>
    <el-button
      class="select"
      icon="el-icon-plus"
      type="warning"
      size="small"
      @click="click"
      style="margin-left:20px"
      >LEC评分</el-button
    >
     
    <el-dialog
      title="请选择风险研判表"
      :modal-append-to-body="false"
      :visible.sync="dialogVisible"
      :before-close="handleClose"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="200px"
        class="demo-ruleForm"
      >
        <el-form-item label="风险研判表">
          <el-select
            v-model="contentId"
            placeholder="风险研判表"
            filterable
            @change="judge"
          >
            <el-option
              v-for="(item, index) in UpperTypelist"
              :key="index"
              :label="item.name"
              :value="item.type"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-dialog
        title="研判表"
        :fullscreen="true"
        :visible.sync="innerVisible"
        append-to-body
      >
        <div id="dialog_div">
          <el-table :data="unitTypelist" border style="width: 100%">
            <el-table-column type="index" label="序号" align="center">
              <template slot-scope="scope">
                <p>{{ scope.$index + 1 }}</p>
              </template>
            </el-table-column>
            <el-table-column
              prop="judgmentContent"
              label="研判内容"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="judgmentBasis"
              label="研判依据"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="judgmentWay" label="研判方法" align="center">
            </el-table-column>
            <el-table-column
              prop="judgmentSituation"
              label="研判情况"
              align="center"
            >
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scoped">
                <el-button
                  v-if="scoped.row.disabled"
                  :disabled="scoped.row.disabled"
                  type="danger"
                >
                  已评分
                </el-button>
                <el-button
                  v-else
                  :disabled="scoped.row.disabled"
                  type="primary"
                  @click="pf(scoped.row)"
                >
                  评分
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <el-dialog v-dialogDrag :visible.sync="innerVisiblesh" append-to-body>
          <span
            slot="title"
            style="font-size:16px;width: 600px;
    display: block;line-height: 30px;"
            >{{ title }}</span
          >
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="200px"
            class="demo-ruleForm"
          >
            <el-form-item label="事故发生的可能性(L)">
              <el-select v-model="ruleForm.ivalue" filterable>
                <el-option
                  v-for="(item, index) in lList"
                  :key="index"
                  :label="item.name"
                  :value="item.num"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="暴露于危险填平的频繁程度(E)">
              <el-select v-model="ruleForm.evalue" filterable>
                <el-option
                  v-for="(item, index) in eList"
                  :key="index"
                  :label="item.name"
                  :value="item.num"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="发生事故产生的后果(C)">
              <el-select v-model="ruleForm.cvalue" filterable>
                <el-option
                  v-for="(item, index) in cList"
                  :key="index"
                  :label="item.name"
                  :value="item.num"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">确定</el-button>
            </el-form-item>
          </el-form>
        </el-dialog>
      </el-dialog>
    </el-dialog>
  </div>
</template>
<script>
import { riskinfoGetList, riskinfoInsert, riskscoregetList } from "@/api/trail";
import "@/utils/dialog";
export default {
  props: ["data"],
  data() {
    return {
      dialogVisible: false,
      innerVisible: false,
      innerVisiblesh: false,
      contentId: "",
      ruleForm: {
        contentId: "",
        ivalue: "",
        evalue: "",
        cvalue: "",
        mineId: 1,
       
      },
      unitTypelist: [],
      lList: [
        {
          num: 10,
          name: "完全可能预料(10分)",
        },
        {
          num: 6,
          name: "相当可能(6分)",
        },
        {
          num: 3,
          name: "可能，但不经常(3分)",
        },
        {
          num: 1,
          name: "可能性小，完全意外(1分)",
        },
        {
          num: 0.5,
          name: "很不可能，可能设想(0.5分)",
        },
        {
          num: 0.2,
          name: "极不可能(0.2分)",
        },
        {
          num: 0.1,
          name: "实际不可能(0.1分)",
        },
      ],
      eList: [
        {
          num: 10,
          name: "连续暴露(10分)",
        },
        {
          num: 6,
          name: "每天工作时间内暴露(6分)",
        },
        {
          num: 3,
          name: "每周一次，或偶然暴露(3分)",
        },
        {
          num: 2,
          name: "每月一次暴露(2分)",
        },
        {
          num: 1,
          name: "每年几次暴露(1分)",
        },
        {
          num: 0.5,
          name: "非常罕见地暴露(0.5分)",
        },
      ],
      cList: [
        {
          num: 100,
          name: "大灾难,许多人死亡。重大隐患、10万元以上罚款。(100分)",
        },
        {
          num: 40,
          name: "灾难,数人死亡。5万以上罚款，停产一个月以上。(100分)",
        },
        {
          num: 15,
          name: "非常严重,一人死亡,1-5万罚款。(15分)",
        },
        {
          num: 7,
          name: "重伤。(7分)",
        },
        {
          num: 3,
          name: "轻伤。(3分)",
        },
        {
          num: 1,
          name: "引人关注,不利于基本的安全卫生要求。(1分)",
        },
      ],
      UpperTypelist: [
        {
          type: 1,
          name: "采掘系统分析研判表",
        },
        {
          type: 2,
          name: "通风系统分析研判表",
        },
        {
          type: 3,
          name: "供电系统分析研判表",
        },
        {
          type: 4,
          name: "防排水系统分析研判表",
        },
        {
          type: 5,
          name: "运输系统分析研判表",
        },
        {
          type: 6,
          name: "安全监控系统分析研判表",
        },
        {
          type: 7,
          name: "应急系统分析研判表",
        },
        {
          type: 8,
          name: "安全管理系统分析研判表",
        },
        {
          type: 9,
          name: "停产停建矿山（或工作面）分析研判表",
        },
        {
          type: 10,
          name: "建设施工项目分析研判表",
        },
      ],
      unitGetlist: [],
      datafrom: {
        unitType: "",
        mineId: 1,
      },
      rules: {
        contentId: [
          { required: true, message: "请选择姓名", trigger: "change" },
        ],
      },
      currentPage: 1,
      pageSize: 1000,
      defaultProps: {
        children: "children",
        label: "name",
        value: "id",
      },
      title: "",
    };
  },
  created() {},
  inject: ["reload"],
  methods: {
    pf(e) {
      this.innerVisiblesh = true;
      this.ruleForm.contentId = e.id;
      (this.ruleForm.ivalue = ""),
        (this.ruleForm.evalue = ""),
        (this.ruleForm.cvalue = ""),
        (this.title = `(研判内容)${e.judgmentContent}`);
    },
    async riskinfoGetList(e) {
      let res = await riskinfoGetList({
        currentPage: 1,
        pageSize: 1000,
        judgmentType: e,
        mineId: 1,
      });

      this.unitTypelist = res.data.list;

      let data = await riskscoregetList({
        mineId: 1,
      });
      const it = data.data.list;

      if (it.length != 0) {
        let obj = this.unitTypelist.filter((item) => {
          return it.some((its) => its.contentId === item.id);
        });
        obj.map((item) => {
          this.$set(item, "disabled", true);
        });
        this.unitTypelist = [...this.unitTypelist, ...obj]; 
      } else {
        this.unitTypelist = res.data.list.map((item) => {
          return Object.assign(item, { disabled: false, txt: "评分" });
        });
   
      
      }
  
      this.innerVisible = true;
    },
    judge(e) {
      this.riskinfoGetList(e);
      console.log(555);
    },
    async onSubmit() {
      let res = await riskinfoInsert(this.ruleForm);

      console.log(res);
      if (res.msg == "success") {
        this.$message({
          message: "成功",
          type: "success",
        });
        this.innerVisiblesh = false;
      }
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    handleClose() {
      this.dialogVisible = false;
      this.reload();
    },
    click() {
      this.dialogVisible = true;
    },
  },
};
</script>
<style lang="scss" scoped>
.el-cascader {
  width: 100%;
}
.el-date-editor {
  width: 100%;
}
</style>
